package com.yunban.project.template.controller;

import cn.hutool.core.lang.tree.Tree;
import com.yunban.project.template.model.dto.StyleReq;
import com.yunban.project.template.service.StyleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
import net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: lijiajun
 * @date: 2024-11-06
 * @version: 1.0
 */
@OperateLog
@RestController
@Tag(name = "模板风格模块")
@RequestMapping("/style-api")
public class StyleController {
    @Resource
    private StyleService styleService;

    @NoNeedLogin
    @GetMapping("/tree")
    @Operation(summary = "获取风格树")
    public List<Tree<Integer>> tree() {
        return this.styleService.tree();
    }

    @PostMapping
    @Operation(summary = "添加风格信息")
    public Boolean saveStyle(@RequestBody @Validated StyleReq req) {
        return this.styleService.saveStyle(req);
    }

    @PutMapping("/{id}")
    @Operation(summary = "修改风格信息")
    public Boolean editStyle(@PathVariable long id, @RequestBody @Validated StyleReq req) {
        return this.styleService.editStyle(id, req);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除风格信息")
    public Boolean delStyle(@PathVariable long id) {
        return this.styleService.delStyle(id);
    }
}
